﻿@model WikeSoft.Enterprise.Models.HolidayModel
@{
    ViewBag.Title = "布局页面";
    Layout = "~/Views/Shared/_Form.cshtml";
    String backUrl = string.Empty;
    if (Request.UrlReferrer != null)
    {
        backUrl = Request.UrlReferrer.ToString();
    }
}


@section scripts
{
    <script type="text/javascript">

        function getFormData() {
            var data = {
                Id:"@Model.Id",
                StartDate: $("#StartDate").val(),
                EndDate: $("#EndDate").val(),
                Remark: $("#Remark").val(),
                Days: $("#Days").val()


            };
            return data;
        }

        $(function () {
            $("#btnWorkFlow").click(function () {
                var data = getFormData();
                var url = "@Url.Action("Edit")";
                var btn = $(this);
                var form = $("#userForm");
                if (form.valid()) {

                    btn.button('loading');
                    $.ajax({
                        url: url,
                        type: "POST",
                        dataType: "json",
                        data: JSON.stringify(data),
                        contentType: "application/json, charset=utf-8",
                        success: function (data) {
                            btn.button('reset');
                            if (data.success) {
                                var ids = [];
                                ids.push(data.data.Id);
                                $.ajax({
                                    url: '@Url.Action("StartWorkFlow")',
                                    type: "POST",
                                    dataType: "json",
                                    data: JSON.stringify({ ids: ids }),
                                    contentType: "application/json, charset=utf-8",
                                    success: function (data) {
                                        if (data.success) {
                                            window.location.href = "@(new MvcHtmlString(backUrl))";
                                        } else {
                                            top.layer.alert("发起流程失败：" + data.message);
                                        }
                                    }

                                });
                            } else {
                                top.layer.alert("添加失败：" + data.message);
                            }
                        }
                    });
                }
            });

            $("#btnSaveData").click(function () {
                var data = getFormData();
                var url = "@Url.Action("Edit")";
                var btn = $(this);
                var form = $("#userForm");
                if (form.valid()) {

                    btn.button('loading');
                    $.ajax({
                        url: url,
                        type: "POST",
                        dataType: "json",
                        data: JSON.stringify(data),
                        contentType: "application/json, charset=utf-8",
                        success: function (data) {
                            btn.button('reset');
                            if (data.success) {
                                window.location.href = "@(new MvcHtmlString(backUrl))";

                            } else {
                                top.layer.alert("添加失败：" + data.message);
                            }
                        }
                    });
                }
            });
        });
    </script>
}


<form class="form-horizontal" action="@Url.Action("Add")" method="post" id="userForm">

    <input type="hidden" id="createFlow" name="createFlow" />

    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                @Html.LabelFor(x => x.StartDate, new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.StartDate, new { @class = "form-control", placeholder = "", onclick = "WdatePicker({ dateFmt: 'yyyy-MM-dd' })" })
                    @Html.ValidationMessageFor(x => x.StartDate)

                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                @Html.LabelFor(x => x.EndDate, new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.EndDate, new { @class = "form-control", placeholder = "", onclick = "WdatePicker({ dateFmt: 'yyyy-MM-dd' })" })
                    @Html.ValidationMessageFor(x => x.EndDate)

                </div>
            </div>
        </div>
    </div>


    <div class="row">
        <div class="col-xs-6">
            <div class="form-group">
                @Html.LabelFor(x => x.Remark, new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextAreaFor(x => x.Remark, new { @class = "form-control", rows = "3", placeholder = "" })
                    @Html.ValidationMessageFor(x => x.Remark)

                </div>
            </div>
        </div>
        <div class="col-xs-6">
            <div class="form-group">
                @Html.LabelFor(x => x.Days, new { @class = "col-sm-2 control-label" })
                <div class="col-sm-10">
                    @Html.TextBoxFor(x => x.Days, new { @class = "form-control", placeholder = "" })
                    @Html.ValidationMessageFor(x => x.Days)

                </div>
            </div>
        </div>
    </div>

    <div>
        <div style="text-align: center">
            <button class="btn btn-default" id="btnSaveData" type="button">保存</button>

            <button class="btn btn-default" id="btnWorkFlow" type="button">提交审批</button>

            <button class="btn btn-default" type="button" action="back" data-url="@(new MvcHtmlString(backUrl))">返回</button>
        </div>

    </div>
</form>
